import 'package:flutter/material.dart';

class BottomButton extends StatelessWidget {
  /// 底部按钮
  const BottomButton({
    Key? key,
    required this.child,
    this.onTap,
    this.enable = true,
    this.primary = true,
  }) : super(key: key);

  final Widget child;

  final GestureTapCallback? onTap;

  /// 阻止点击事件
  final bool enable;

  /// 主题色样式
  final bool primary;

  @override
  Widget build(BuildContext context) {
    final fontColor = primary ? Colors.white : Colors.grey;
    final backColor = primary ? Colors.pink : Colors.green;
    return GestureDetector(
      onTap: enable ? onTap : null,
      child: AnimatedOpacity(
        duration: const Duration(milliseconds: 250),
        opacity: enable ? 1 : 0.7,
        child: Container(
          width: MediaQuery.of(context).size.width / 2, // 容器宽度的一半
          height: 36,
          decoration: BoxDecoration(
            color: backColor,
            borderRadius: BorderRadius.circular(36),
          ),
          alignment: Alignment.center,
          child: DefaultTextStyle(
            style: TextStyle(
              color: fontColor,
              fontSize: 14,
              fontWeight: FontWeight.w500,
              fontFamilyFallback: const ['PingFang SC'],
            ),
            child: child,
          ),
        ),
      ),
    );
  }
}
